/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = 'regional';
  @endpointMap = {
    ap-northeast-1 = 'agency.aliyuncs.com',
    ap-northeast-2-pop = 'agency.aliyuncs.com',
    ap-south-1 = 'agency.aliyuncs.com',
    ap-southeast-2 = 'agency.aliyuncs.com',
    ap-southeast-3 = 'agency.aliyuncs.com',
    ap-southeast-5 = 'agency.aliyuncs.com',
    cn-beijing = 'agency.aliyuncs.com',
    cn-beijing-finance-1 = 'agency.aliyuncs.com',
    cn-beijing-finance-pop = 'agency.aliyuncs.com',
    cn-beijing-gov-1 = 'agency.aliyuncs.com',
    cn-beijing-nu16-b01 = 'agency.aliyuncs.com',
    cn-chengdu = 'agency.aliyuncs.com',
    cn-edge-1 = 'agency.aliyuncs.com',
    cn-fujian = 'agency.aliyuncs.com',
    cn-haidian-cm12-c01 = 'agency.aliyuncs.com',
    cn-hangzhou = 'agency.aliyuncs.com',
    cn-hangzhou-bj-b01 = 'agency.aliyuncs.com',
    cn-hangzhou-finance = 'agency.aliyuncs.com',
    cn-hangzhou-internal-prod-1 = 'agency.aliyuncs.com',
    cn-hangzhou-internal-test-1 = 'agency.aliyuncs.com',
    cn-hangzhou-internal-test-2 = 'agency.aliyuncs.com',
    cn-hangzhou-internal-test-3 = 'agency.aliyuncs.com',
    cn-hangzhou-test-306 = 'agency.aliyuncs.com',
    cn-hongkong = 'agency.aliyuncs.com',
    cn-hongkong-finance-pop = 'agency.aliyuncs.com',
    cn-huhehaote = 'agency.aliyuncs.com',
    cn-huhehaote-nebula-1 = 'agency.aliyuncs.com',
    cn-north-2-gov-1 = 'agency.aliyuncs.com',
    cn-qingdao = 'agency.aliyuncs.com',
    cn-qingdao-nebula = 'agency.aliyuncs.com',
    cn-shanghai = 'agency.aliyuncs.com',
    cn-shanghai-et15-b01 = 'agency.aliyuncs.com',
    cn-shanghai-et2-b01 = 'agency.aliyuncs.com',
    cn-shanghai-finance-1 = 'agency.aliyuncs.com',
    cn-shanghai-inner = 'agency.aliyuncs.com',
    cn-shanghai-internal-test-1 = 'agency.aliyuncs.com',
    cn-shenzhen = 'agency.aliyuncs.com',
    cn-shenzhen-finance-1 = 'agency.aliyuncs.com',
    cn-shenzhen-inner = 'agency.aliyuncs.com',
    cn-shenzhen-st4-d01 = 'agency.aliyuncs.com',
    cn-shenzhen-su18-b01 = 'agency.aliyuncs.com',
    cn-wuhan = 'agency.aliyuncs.com',
    cn-wulanchabu = 'agency.aliyuncs.com',
    cn-yushanfang = 'agency.aliyuncs.com',
    cn-zhangbei = 'agency.aliyuncs.com',
    cn-zhangbei-na61-b01 = 'agency.aliyuncs.com',
    cn-zhangjiakou = 'agency.aliyuncs.com',
    cn-zhangjiakou-na62-a01 = 'agency.aliyuncs.com',
    cn-zhengzhou-nebula-1 = 'agency.aliyuncs.com',
    eu-central-1 = 'agency.aliyuncs.com',
    eu-west-1 = 'agency.aliyuncs.com',
    eu-west-1-oxs = 'agency.aliyuncs.com',
    me-east-1 = 'agency.aliyuncs.com',
    rus-west-1-pop = 'agency.aliyuncs.com',
    us-east-1 = 'agency.aliyuncs.com',
    us-west-1 = 'agency.aliyuncs.com',
  };

  checkConfig(config);
  @endpoint = getEndpoint('agency', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model QueryConsumeInstancesRequest {
  commodityCode?: string(name='CommodityCode'),
  consumeCategory?: string(name='ConsumeCategory'),
  endTime?: string(name='EndTime'),
  needDetail?: boolean(name='NeedDetail'),
  ownerAccount?: string(name='OwnerAccount'),
  pageMinId?: long(name='PageMinId'),
  pageSize?: int32(name='PageSize'),
  startTime?: string(name='StartTime'),
}

model QueryConsumeInstancesResponseBody = {
  code?: string(name='Code'),
  currentPage?: int32(name='CurrentPage'),
  data?: {
    consumeInstanceModel?: [ 
    {
      buyerId?: long(name='BuyerId'),
      cashPayAmount?: string(name='CashPayAmount'),
      commodityCode?: string(name='CommodityCode'),
      consumeAmount?: string(name='ConsumeAmount'),
      consumeCategory?: string(name='ConsumeCategory'),
      consumeDetailMap?: string(name='ConsumeDetailMap'),
      consumePeriod?: string(name='ConsumePeriod'),
      consumeTime?: string(name='ConsumeTime'),
      couponPayAmount?: string(name='CouponPayAmount'),
      freeAmount?: string(name='FreeAmount'),
      instanceId?: string(name='InstanceId'),
      instanceNick?: string(name='InstanceNick'),
      internetIp?: string(name='InternetIp'),
      intranetIp?: string(name='IntranetIp'),
      ownerId?: long(name='OwnerId'),
      payStatus?: string(name='PayStatus'),
      region?: string(name='Region'),
      requireAmount?: string(name='RequireAmount'),
      serviceDuration?: string(name='ServiceDuration'),
      serviceEndTime?: string(name='ServiceEndTime'),
      serviceStartTime?: string(name='ServiceStartTime'),
      tag?: string(name='Tag'),
      unclearAmount?: string(name='UnclearAmount'),
      bizId?: long(name='bizId'),
    }
  ](name='ConsumeInstanceModel')
  }(name='Data'),
  message?: string(name='Message'),
  nextPageMinId?: long(name='NextPageMinId'),
  pageSize?: int32(name='PageSize'),
  success?: boolean(name='Success'),
  totalCount?: int32(name='TotalCount'),
}

model QueryConsumeInstancesResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: QueryConsumeInstancesResponseBody(name='body'),
}

async function queryConsumeInstancesWithOptions(request: QueryConsumeInstancesRequest, runtime: Util.RuntimeOptions): QueryConsumeInstancesResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.commodityCode)) {
    query['CommodityCode'] = request.commodityCode;
  }
  if (!Util.isUnset(request.consumeCategory)) {
    query['ConsumeCategory'] = request.consumeCategory;
  }
  if (!Util.isUnset(request.endTime)) {
    query['EndTime'] = request.endTime;
  }
  if (!Util.isUnset(request.needDetail)) {
    query['NeedDetail'] = request.needDetail;
  }
  if (!Util.isUnset(request.ownerAccount)) {
    query['OwnerAccount'] = request.ownerAccount;
  }
  if (!Util.isUnset(request.pageMinId)) {
    query['PageMinId'] = request.pageMinId;
  }
  if (!Util.isUnset(request.pageSize)) {
    query['PageSize'] = request.pageSize;
  }
  if (!Util.isUnset(request.startTime)) {
    query['StartTime'] = request.startTime;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'QueryConsumeInstances',
    version = '2016-11-18',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function queryConsumeInstances(request: QueryConsumeInstancesRequest): QueryConsumeInstancesResponse {
  var runtime = new Util.RuntimeOptions{};
  return queryConsumeInstancesWithOptions(request, runtime);
}

